let express = require("express");
let time = require("time-stamp");
let index = require("./router/index")
let ico = require("serve-favicon")
let app = express();

// express.urlencoded内置中间件可以解析表单请求体中的数据
app.use(express.urlencoded({extended:false}))

// express.json()作用:解析请求体中的json数据变成对象，添加到req的body上面
app.use(express.json());

// 加载ico
app.use(ico("./public/1.ico"));

// 自定义中间件
app.use("/",(request,response,next) => {
    // response.send("网站正在维护中...")
    request.time = time(".今天是YYYY年MM月DD日");
    next();
})


// 路由模块
app.use("/",index);

// 错误
app.use((request,response) => {
    response.send("对不起，找不到网页")
})


// 启动监听
app.listen(3000,() => {
    console.log("http://localhost:3000");
});